package com.aft.terra.modules.game.model;

import java.util.List;

import com.aft.terra.common.utils.DateUtil;
import com.aft.terra.modules.game.model.base.BaseWinning;
import com.jfinal.plugin.activerecord.Db;

public class Winning extends BaseWinning<Winning> {

	private static final long serialVersionUID = 1L;

	public static final Winning dao = new Winning();
	
	/**
	 * 根据时间段来查询
	 * @param userId 用户id
	 * @param date 时间 
	 * @return
	 */
	public Integer queryUserId(Long userId,String date) {
		StringBuilder sql = new StringBuilder();
		sql.append("select count(*)  from t_winning where user_id = ? ")
			.append(" and createDate between '")
		    .append(date)
		    .append(" 00:00:00'")
		    .append(" and '")
		    .append(date)
		    .append(" 23:59:59'");
		return Db.queryLong(sql.toString(), userId).intValue();
	}
	
	/**
	 * 只查询五元话费
	 * @return
	 */
	public List<Winning> getPrizeList(){
		StringBuilder sql = new StringBuilder();
		sql.append("select w.*,u.d_user_name user_name, ")
			.append("(select w_headimgurl from t_wechat where id = u.d_wechat_id) w_headimgurl ")
		    .append(" from t_winning w join t_user u on w.user_id = u.id and w.lucky_id is not null ")
		    .append("  AND w.createDate BETWEEN ")
		    .append(DateUtil.nowDateBegin())
		    .append( " AND ")
		    .append(DateUtil.nowDateEnd())
		    .append(" order by w.createDate desc limit 50");
		return find(sql.toString());
	}
	
}
